package com.qf.data.api;

import com.qf.common.bean.R;
import com.qf.data.service.CheckCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.web.bind.annotation.*;

/**
 * 保存获取短信验证码到redis
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/data/checkcode")
public class CheckCodeController {

    @Autowired
    private CheckCodeService checkCodeService;

    /**
     * 保存短信验证码到redis中
     * @return
     */
    @PostMapping("/saveToRedis")
    public R saveToRedis(@RequestParam(value = "phone") String phone
            , @RequestParam(value = "code")String code) {
        R result = checkCodeService.saveToRedis(phone, code);
        return result;
    }

    /**
     * 根据手机号获取验证码
     * @param phone
     * @return
     */
    @GetMapping("/getCode/{phone}")
    public R<String> getCode(@PathVariable(value = "phone") String phone) {
        R<String> result = checkCodeService.getCode(phone);
        return result;
    }
}
